package com.lsh.payment.core.service.async.impl;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.lsh.payment.core.dao.paylog.PayLogDao;
import com.lsh.payment.core.model.log.PayLog;
import com.lsh.payment.core.service.async.IEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Project Name: lsh-payment
 * @author by jingyuan
 * Date: 16/12/22
 * 北京链商电子商务有限公司
 * Package com.lsh.payment.core.service.AsyncService
 * desc:异步处理监听类
 */
@Component
public class LogEventListener implements IEventListener {

    private Logger logger = LoggerFactory.getLogger(LogEventListener.class);

    @Autowired
    private PayLogDao payLogDao;

    /**
     * 插入日志表
     *
     * @param payLog 日志类
     */
    @Subscribe
    @AllowConcurrentEvents
    public void addPayLog(PayLog payLog) {
        try {
            payLogDao.insertSelective(payLog);
        } catch (Exception e) {
            logger.error("记录日志异常", e);
        }
    }

}
